/*
 * @Descripttion:
 * @LastEditors: xzh
 * @LastEditTime: 2023-11-20 23:58:47
 */

import Dile_Methods from "@/utils/methods";
import { object_Inf } from "@/utils/typings/index.type";
import {
  chartFiel_Y,
  produceChartColorMap,
  produceDataTypeEnum,
} from "./index.type";
import Base_Echart from "../../echartOperate/base";
import i18n from "@/international/i18n";

/*
 * @Descripttion:产出数-数据类型工具类
 * @LastEditors: xzh
 * @LastEditTime: 2023-10-11 21:24:02
 */
export default class ProduceDashboardUtils {
  /**
   * @Author: xzh
   * @Descripttion: 多语言实例
   * @Param:
   */
  static t = i18n().global.t;
  /**
   * @Author: xzh
   * @Descripttion:表格列映射
   * @Param:
   */
  static tableColumnMap: object_Inf = {
    //AOI 良率
    [produceDataTypeEnum.aoi]: [
      {
        field: "equipmentName",
        //t('page.dashboardManageArr.produceDashboardArr.aoiArr.equipCode')
        title: "page.dashboardManageArr.produceDashboardArr.aoiArr.equipCode",
        width: 100,
      },
      {
        field: "aoiYieldRate",
        //t('page.dashboardManageArr.produceDashboardArr.aoiArr.aoiYieldRate')
        title:
          "page.dashboardManageArr.produceDashboardArr.aoiArr.aoiYieldRate",
        unit: "%",
      },
      {
        field: "inspectionQuantity",
        //t('page.dashboardManageArr.produceDashboardArr.aoiArr.inspectionQuantity')
        title:
          "page.dashboardManageArr.produceDashboardArr.aoiArr.inspectionQuantity",
      },
      {
        field: "yieldQuantity",
        //t('page.dashboardManageArr.produceDashboardArr.aoiArr.yieldQuantity')
        title:
          "page.dashboardManageArr.produceDashboardArr.aoiArr.yieldQuantity",
      },
    ],
    //成型制程产出数
    [produceDataTypeEnum.formingOutput]: [
      {
        field: "equipmentName",
        //t('page.equipManageArr.equipArchivesArr.code')
        title: "page.equipManageArr.equipArchivesArr.code",
        width: 100,
      },
      {
        field: "outputQuantity",
        //t('page.dashboardManageArr.produceDashboardArr.outputQuantity')
        title: "page.dashboardManageArr.produceDashboardArr.outputQuantity",
      },
      {
        field: "mouldTimes",
        //t('page.dashboardManageArr.produceDashboardArr.mouldTimes')
        title: "page.dashboardManageArr.produceDashboardArr.mouldTimes",
      },
      {
        field: "mouldCavityNum",
        //t('page.dashboardManageArr.produceDashboardArr.mouldCavityNum')
        title: "page.dashboardManageArr.produceDashboardArr.mouldCavityNum",
      },
    ],
    //切箍边制程产出数
    [produceDataTypeEnum.cutEdgeOutput]: [
      {
        field: "equipmentName",
        //t('page.equipManageArr.equipArchivesArr.code')
        title: "page.equipManageArr.equipArchivesArr.code",
        width: 100,
      },
      {
        field: "outputQuantity",
        //t('page.dashboardManageArr.produceDashboardArr.outputQuantity')
        title: "page.dashboardManageArr.produceDashboardArr.outputQuantity",
      },
      {
        field: "mouldTimes",
        //t('page.dashboardManageArr.produceDashboardArr.mouldTimes')
        title: "page.dashboardManageArr.produceDashboardArr.mouldTimes",
      },
      {
        field: "mouldCavityNum",
        //t('page.dashboardManageArr.produceDashboardArr.mouldCavityNum')
        title: "page.dashboardManageArr.produceDashboardArr.mouldCavityNum",
      },
    ],
    //各AOI/CCD检验数
    [produceDataTypeEnum.aoiTestNum]: [
      {
        field: "equipmentName",
        //t('page.equipManageArr.equipArchivesArr.code')
        title: "page.equipManageArr.equipArchivesArr.code",
        width: 100,
      },
      {
        field: "aoiYieldRate",
        //t('page.dashboardManageArr.produceDashboardArr.aoiYieldRate')
        title: "page.dashboardManageArr.produceDashboardArr.aoiYieldRate",
        unit: "%",
      },
      {
        field: "inspectionQuantity",
        //t('page.dashboardManageArr.produceDashboardArr.inspectionQuantity')
        title: "page.dashboardManageArr.produceDashboardArr.inspectionQuantity",
      },
      {
        field: "yieldQuantity",
        //t('page.dashboardManageArr.produceDashboardArr.yieldQuantity')
        title: "page.dashboardManageArr.produceDashboardArr.yieldQuantity",
      },
    ],
    //各AOI/CCD不良率
    [produceDataTypeEnum.aoiDefectRate]: [
      {
        field: "equipmentName",
        //t('page.equipManageArr.equipArchivesArr.code')
        title: "page.equipManageArr.equipArchivesArr.code",
        width: 100,
      },
      {
        field: "aoiBadRate",
        //t('page.dashboardManageArr.produceDashboardArr.aoiNotYieldRate')
        title: "page.dashboardManageArr.produceDashboardArr.aoiNotYieldRate",
        unit: "%",
      },
      {
        field: "inspectionQuantity",
        //t('page.dashboardManageArr.produceDashboardArr.inspectionQuantity')
        title: "page.dashboardManageArr.produceDashboardArr.inspectionQuantity",
      },
      {
        field: "ngNumber",
        //t('page.dashboardManageArr.produceDashboardArr.notYieldQuantity')
        title: "page.dashboardManageArr.produceDashboardArr.notYieldQuantity",
      },
    ],
    //堆叠制程产出数
    [produceDataTypeEnum.stackingOutput]: [
      {
        field: "equipmentName",
        //t('page.equipManageArr.equipArchivesArr.code')
        title: "page.equipManageArr.equipArchivesArr.code",
        width: 100,
      },
      {
        field: "startNumber",
        //t('page.dashboardManageArr.produceDashboardArr.startNumber')
        title: "page.dashboardManageArr.produceDashboardArr.startNumber",
      },
      {
        field: "endNumber",
        //t('page.dashboardManageArr.produceDashboardArr.endNumber')
        title: "page.dashboardManageArr.produceDashboardArr.endNumber",
      },
      {
        field: "outputQuantity",
        //t('page.dashboardManageArr.produceDashboardArr.outputQuantity')
        title: "page.dashboardManageArr.produceDashboardArr.outputQuantity",
      },
    ],
    //成型设备稼动率
    [produceDataTypeEnum.formingUtilization]: [
      {
        field: "equipmentName",
        //t('page.equipManageArr.equipArchivesArr.code')
        title: "page.equipManageArr.equipArchivesArr.code",
        width: 100,
      },
      {
        field: "actualWorkingHour",
        //t('page.dashboardManageArr.produceDashboardArr.actualWorkingHour')
        title: "page.dashboardManageArr.produceDashboardArr.actualWorkingHour",
        unit: "H",
      },
      {
        field: "standardWorkingHour",
        //t('page.dashboardManageArr.produceDashboardArr.standardWorkingHour')
        title:
          "page.dashboardManageArr.produceDashboardArr.standardWorkingHour",
        unit: "H",
      },
      {
        field: "utilizationRate",
        //t('page.dashboardManageArr.produceDashboardArr.utilizationRate')
        title: "page.dashboardManageArr.produceDashboardArr.utilizationRate",
        unit: "%",
      },
    ],
    //切箍边设备稼动率
    [produceDataTypeEnum.cutEdgeUtilization]: [
      {
        field: "equipmentName",
        //t('page.equipManageArr.equipArchivesArr.code')
        title: "page.equipManageArr.equipArchivesArr.code",
        width: 100,
      },
      {
        field: "actualWorkingHour",
        //t('page.dashboardManageArr.produceDashboardArr.actualWorkingHour')
        title: "page.dashboardManageArr.produceDashboardArr.actualWorkingHour",
        unit: "H",
      },
      {
        field: "standardWorkingHour",
        //t('page.dashboardManageArr.produceDashboardArr.standardWorkingHour')
        title:
          "page.dashboardManageArr.produceDashboardArr.standardWorkingHour",
        unit: "H",
      },
      {
        field: "utilizationRate",
        //t('page.dashboardManageArr.produceDashboardArr.utilizationRate')
        title: "page.dashboardManageArr.produceDashboardArr.utilizationRate",
        unit: "%",
      },
    ],
    //AOI设备稼动率
    [produceDataTypeEnum.aoiUtilization]: [
      {
        field: "equipmentName",
        //t('page.equipManageArr.equipArchivesArr.code')
        title: "page.equipManageArr.equipArchivesArr.code",
        width: 100,
      },
      {
        field: "actualWorkingHour",
        //t('page.dashboardManageArr.produceDashboardArr.actualWorkingHour')
        title: "page.dashboardManageArr.produceDashboardArr.actualWorkingHour",
        unit: "H",
      },
      {
        field: "standardWorkingHour",
        //t('page.dashboardManageArr.produceDashboardArr.standardWorkingHour')
        title:
          "page.dashboardManageArr.produceDashboardArr.standardWorkingHour",
        unit: "H",
      },
      {
        field: "utilizationRate",
        //t('page.dashboardManageArr.produceDashboardArr.utilizationRate')
        title: "page.dashboardManageArr.produceDashboardArr.utilizationRate",
        unit: "%",
      },
    ],
    //成型机整体利用率
    [produceDataTypeEnum.formingUseRate]: [
      {
        field: "equipmentName",
        //t('page.equipManageArr.equipArchivesArr.code')
        title: "page.equipManageArr.equipArchivesArr.code",
        width: 100,
      },
      {
        field: "actualWorkingHour",
        //t('page.dashboardManageArr.produceDashboardArr.actualPowerOnHour')
        title: "page.dashboardManageArr.produceDashboardArr.actualPowerOnHour",
        unit: "H",
      },
      {
        field: "standardWorkingHour",
        //t('page.dashboardManageArr.produceDashboardArr.standardPowerOnHour')
        title:
          "page.dashboardManageArr.produceDashboardArr.standardPowerOnHour",
        unit: "H",
      },
      {
        field: "usageRate",
        //t('page.dashboardManageArr.produceDashboardArr.useRate')
        title: "page.dashboardManageArr.produceDashboardArr.useRate",
        unit: "%",
      },
    ],
  };
  /**
   * @Author: xzh
   * @Descripttion: 获取生成图表
   * @Param:
   * @param {produceDataTypeEnum} dataType 数据类型
   * @param {string} dateType 时间类型
   * @param {Array} dataArr 数据源
   */
  static getProduceChart(
    dataType: produceDataTypeEnum,
    dateType: string,
    dataArr: Array<object_Inf>
  ) {
    switch (dataType) {
      // case produceDataTypeEnum.formingUtilization:
      // case produceDataTypeEnum.cutEdgeUtilization:
      // case produceDataTypeEnum.aoiUtilization:
      //   //成型稼动率&&切边稼动率&&aoi稼动率
      //   return this.getUtilizationRateChart(dataType, dataArr);
      //   break;
      // case produceDataTypeEnum.inBoundCumulant:
      //   //累计入库量
      //   return this.getInBoundCumulantChart(dataType, dataArr);
      // break;
      default:
        return this.getOutPutChart(dataType, dataArr);
        break;
    }
  }

  /**
   * @Author: xzh
   * @Descripttion: 获取产出量图表
   * @Param:
   */
  static getOutPutChart(
    dataType: produceDataTypeEnum,
    dataArr: Array<object_Inf>
  ) {
    let yField = chartFiel_Y[dataType] || "outputQuantity";
    return {
      option: {
        tooltip: {
          trigger: "item",
        },
        color: [produceChartColorMap[dataType] || "#4472c4"],
        xAxis: {
          type: "category",
          data: dataArr.map((x: object_Inf) => x.equipmentName),
        },
        yAxis: {
          type: "value",
          axisLabel: {
            formatter: `{value}${
              !!ProduceDashboardUtils.isDecimals(dataType) ? "%" : ""
            }`,
          },
        },
        grid: {
          top: "3%",
          bottom: "28",
          left: "1%",
          right: "1%",
          containLabel: true,
        },
        dataZoom: [
          {
            type: "inside",
          },
          {
            type: "slider",
            height: 13, // 横条高度
            moveHandleSize: 0,
            selectedDataBackground: {
              lineStyle: {
                opacity: 0,
                color: "#e7efff",
              },
              areaStyle: {
                opacity: 0,
              },
            },
            handleIcon:
              "M-292,322.2c-3.2,0-6.4-0.6-9.3-1.9c-2.9-1.2-5.4-2.9-7.6-5.1s-3.9-4.8-5.1-7.6c-1.3-3-1.9-6.1-1.9-9.3c0-3.2,0.6-6.4,1.9-9.3c1.2-2.9,2.9-5.4,5.1-7.6s4.8-3.9,7.6-5.1c3-1.3,6.1-1.9,9.3-1.9c3.2,0,6.4,0.6,9.3,1.9c2.9,1.2,5.4,2.9,7.6,5.1s3.9,4.8,5.1,7.6c1.3,3,1.9,6.1,1.9,9.3c0,3.2-0.6,6.4-1.9,9.3c-1.2,2.9-2.9,5.4-5.1,7.6s-4.8,3.9-7.6,5.1C-285.6,321.5-288.8,322.2-292,322.2z",
          },
        ],
        series: [
          {
            data: dataArr.map((x: object_Inf) => x[yField]),
            type: "bar",
          },
        ],
      },
      id: Dile_Methods.newGuid(),
    };
  }
  /**
   * @Author: xzh
   * @Descripttion: 获取稼动率图表
   * @Param:
   */
  static getUtilizationRateChart(
    dataType: produceDataTypeEnum,
    dataArr: Array<object_Inf>
  ) {
    let data = {
      xAxis: dataArr.map((x: object_Inf) => x.equipmentName),
      minMaxArr: [{}, { min: 0, max: 120 }],
      dataArr: [
        {
          // name: "设备标准工时(小时)",
          name: this.t(
            "page.dashboardManageArr.produceDashboardArr.standardWorkingHour"
          ),
          type: "bar",
          data: dataArr.map((x: object_Inf) => x.standardWorkingHour || 0),
        },
        {
          name: this.t(
            "page.dashboardManageArr.produceDashboardArr.utilizationRate"
          ),
          type: "line",
          suffix: "%",
          minMaxIndex: 1,
          labelShow: false,
          data: dataArr.map((x: object_Inf) => x.utilizationRate || 0),
        },
      ],
    };
    return Base_Echart.formatChartData_bar(
      {
        ...data,
        color: [produceChartColorMap[dataType], "#ffc000"],
      },
      {
        cover: {
          grid: {
            top: "3%",
            bottom: "28",
            left: "1%",
            right: "1%",
            containLabel: true,
          },
          dataZoom: [
            {
              type: "inside",
            },
            {
              type: "slider",
              height: 13, // 横条高度
              moveHandleSize: 0,
              selectedDataBackground: {
                lineStyle: {
                  opacity: 0,
                  color: "#e7efff",
                },
                areaStyle: {
                  opacity: 0,
                },
              },
              handleIcon:
                "M-292,322.2c-3.2,0-6.4-0.6-9.3-1.9c-2.9-1.2-5.4-2.9-7.6-5.1s-3.9-4.8-5.1-7.6c-1.3-3-1.9-6.1-1.9-9.3c0-3.2,0.6-6.4,1.9-9.3c1.2-2.9,2.9-5.4,5.1-7.6s4.8-3.9,7.6-5.1c3-1.3,6.1-1.9,9.3-1.9c3.2,0,6.4,0.6,9.3,1.9c2.9,1.2,5.4,2.9,7.6,5.1s3.9,4.8,5.1,7.6c1.3,3,1.9,6.1,1.9,9.3c0,3.2-0.6,6.4-1.9,9.3c-1.2,2.9-2.9,5.4-5.1,7.6s-4.8,3.9-7.6,5.1C-285.6,321.5-288.8,322.2-292,322.2z",
            },
          ],
        },
      }
    );
  }
  /**
   * @Author: xzh
   * @Descripttion: 获取累计订单量图表
   * @Param:
   */
  static getInBoundCumulantChart(
    dataType: produceDataTypeEnum,
    dataArr: Array<object_Inf>
  ) {
    let data = {
      xAxis: dataArr.map((x: object_Inf) => x.orderCode),
      minMaxArr: [{}, {}],
      dataArr: [
        {
          name: this.t(
            "page.dashboardManageArr.produceDashboardArr.orderQuantity"
          ),
          type: "bar",
          data: dataArr.map((x: object_Inf) => x.orderQuantity || 0),
        },
        {
          name: this.t(
            "page.dashboardManageArr.produceDashboardArr.stockInQuantity"
          ),
          type: "line",
          minMaxIndex: 1,
          labelShow: false,
          data: dataArr.map((x: object_Inf) => x.stockInQuantity || 0),
        },
      ],
    };
    return Base_Echart.formatChartData_bar(
      {
        ...data,
        color: ["#00B050", "#ED7D31"],
      },
      {
        cover: {
          grid: {
            top: "3%",
            bottom: "28",
            left: "1%",
            right: "1%",
            containLabel: true,
          },
          dataZoom: [
            {
              type: "inside",
            },
            {
              type: "slider",
              height: 13, // 横条高度
              moveHandleSize: 0,
              selectedDataBackground: {
                lineStyle: {
                  opacity: 0,
                  color: "#e7efff",
                },
                areaStyle: {
                  opacity: 0,
                },
              },
              handleIcon:
                "M-292,322.2c-3.2,0-6.4-0.6-9.3-1.9c-2.9-1.2-5.4-2.9-7.6-5.1s-3.9-4.8-5.1-7.6c-1.3-3-1.9-6.1-1.9-9.3c0-3.2,0.6-6.4,1.9-9.3c1.2-2.9,2.9-5.4,5.1-7.6s4.8-3.9,7.6-5.1c3-1.3,6.1-1.9,9.3-1.9c3.2,0,6.4,0.6,9.3,1.9c2.9,1.2,5.4,2.9,7.6,5.1s3.9,4.8,5.1,7.6c1.3,3,1.9,6.1,1.9,9.3c0,3.2-0.6,6.4-1.9,9.3c-1.2,2.9-2.9,5.4-5.1,7.6s-4.8,3.9-7.6,5.1C-285.6,321.5-288.8,322.2-292,322.2z",
            },
          ],
        },
      }
    );
  }
  /**
   * @Author: xzh
   * @Descripttion: 判断是否为小数
   * @Param:
   * @param {produceDataTypeEnum} type
   */
  static isDecimals = (type: string) => {
    return !![
      produceDataTypeEnum.aoi,
      produceDataTypeEnum.aoiDefectRate,
      produceDataTypeEnum.formingUtilization,
      produceDataTypeEnum.cutEdgeUtilization,
      produceDataTypeEnum.aoiUtilization,
      produceDataTypeEnum.formingUseRate,
    ].includes(type as produceDataTypeEnum);
  };
}
